#include "Particle.h"

//Powerful constructor
CParticle::CParticle(float prmLifetime,
	SGD::Size prmSize,
	SGD::Point prmPos,
	SGD::Vector prmVel,
	SGD::Color prmColor,
	float prmAlpha,
	float prmScale,
	float prmCurRot,
	SGD::Vector prmRotVel, float prmRespawnRate)
{
	//Initialization
	this->m_fCurrentLife = this->m_fLifetime = prmLifetime;
	this->m_sizSize = prmSize;
	this->m_poiPos = prmPos;
	this->m_vecVelocity = prmVel;
	this->m_colColor = prmColor;
	this->m_fAlpha = prmAlpha;
	this->m_fScale = prmScale;
	this->m_fCurRot = prmCurRot;
	this->m_vecRotationVelocity = prmRotVel;
	this->m_fRespawnRate = m_fSpawnRate = prmRespawnRate;
	m_bAlive = false;
}

void CParticle::Update(float _elapsedTime,SGD::Point prmEmitPos)
{


	if (m_bAlive)
	{
		//movement
		m_poiPos += m_vecVelocity * _elapsedTime;
		//decaying lifetime
		this->m_fCurrentLife -= _elapsedTime;

		//I am dead
		if (m_fCurrentLife <= 0)
		{
			m_bAlive = false;
			m_fCurrentLife = m_fLifetime;
		}
	}
	else
	{
		//waiting to be reborn
		this->m_fRespawnRate -= _elapsedTime;
		if (m_fRespawnRate <= 0)
		{
			m_bAlive = true;
			m_poiPos = prmEmitPos;
			m_fRespawnRate = m_fSpawnRate;
			
		}
	}

}

float CParticle::FindCurrentSize()
{
	return 0;
}

void CParticle::GiveLife()
{
	m_bAlive = true;

}